package com.aboo.users.action;

import com.aboo.frame.vo.ReturnVO;
import com.aboo.users.domain.UserPO;
import com.aboo.users.service.UserService;
import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/users")
public class UserAction {

    @Resource
    private UserService userService;

    @RequestMapping("/getUser")
    public ReturnVO<List<UserPO>> getUser(String pageNo, String pageSize) {
        ReturnVO<List<UserPO>> rv = new ReturnVO<>();

        List<UserPO> list = userService.getUser(pageNo, pageSize);
        log.info(JSONArray.toJSONString(list));

        rv.setData(list);
        return rv;
    }

    @RequestMapping("/saveUser")
    public ReturnVO<Object> saveUser(UserPO user) {
        ReturnVO<Object> rv = new ReturnVO<>();

        userService.saveUser(user);
        log.info(user.toString());
        return rv;
    }

    @RequestMapping("/modifyUser")
    public ReturnVO<Object> modifyUser(UserPO user) {
        ReturnVO<Object> rv = new ReturnVO<>();

        userService.modifyUser(user);
        log.info(user.toString());
        return rv;
    }

}
